<html>
<head>
  <title>UCD APP V1.1
</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <script type="text/javascript" src="http://www.google.com/jsapi?key=ABQIAAAAwbkbZLyhsmTCWXbTcjbgbRSzHs7K5SvaUdm8ua-Xxy_-2dYwMxQMhnagaawTo7L1FE1-amhuQxIlXw"></script>
  
   <applet code="readFileApplet.class" name="getdata" width=0 height=0>
   </applet>

  
  <style type="text/css">
    @import "http://ajax.googleapis.com/ajax/libs/dojo/1.2.3/dijit/themes/tundra/tundra.css";
    @import "http://ajax.googleapis.com/ajax/libs/dojo/1.2.3/dojo/resources/dojo.css";
  </style>
  

  <script type="text/javascript">

  var ge;
  var la;
  var latitude;
  var longitude;
  var heading;
  var buildings;
  var turning;
  var frameendEL;
  var kmzs;
  var nls;
  var geocoder;
  var kmlUrl=null;
  var arr = new Array();
  var kmlObjectsArray=new Array();
   var current=0;
   google.load("earth", "1");
  google.load("maps", "2.99");
  /*function initialize() {
      var map = new GMap2(document.getElementById("map"));
      map.setCenter(new GLatLng(53.307632,-6.221766), 15);
      map.addMapType(G_SATELLITE_3D_MAP);
      map.addControl(new GHierarchicalMapTypeControl());
      map.addControl(new GLargeMapControl());
      map.getEarthInstance(getEarthInstanceCB);
    }*/
  
function init() {
    geocoder = new GClientGeocoder();
    google.earth.createInstance('map3d', getEarthInstanceCB, failureCB);
    var scptmap = document.createElement('script');
    scptmap.src = 'mapoption.js';
    document.body.appendChild(scptmap);
    
  }
  
 function getEarthInstanceCB(instance) {
    ge = instance;
    ge.getWindow().setVisibility(true);
  
    frameendEL = false;
    buildings = false;
  
   
    toggleBuildings();
	 
    ge.getNavigationControl().setVisibility(ge.VISIBILITY_AUTO);
    
    ge.getLayerRoot().enableLayerById(ge.LAYER_BORDERS, true);
   // ge.getLayerRoot().enableLayerById(ge.LAYER_ROADS, true);
    ge.getLayerRoot().enableLayerById(ge.LAYER_TERRAIN,true);
    
    la = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);
     
    
	
	
    create3dModel();
   setInterval('UpdKMLbytime()',10000);
    //document.getElementById('installed-plugin-version').innerHTML =
   // ge.getPluginVersion().toString();
	var win = ge.getWindow();
    updateOptions();
   }
  
   
 
 function UpdKMLbytime(){
                arr=document.getdata.update();
                if(kmlObjectsArray.length>0){
                    for(current=0;current<arr.length;current++){
                    ge.getFeatures().removeChild(kmlObjectsArray[current]);
					
				  }
                   
                  }
				  current=0;
		   for(i=0;i<arr.length;i++){
		   
                kmlUrl='http://193.1.132.19/svn/spiderrepository/lei/UCDapp/'+arr[i]+'.kml';
		   google.earth.fetchKml(ge, kmlUrl, function finishfirstFetchKml(kmlObject){
			     if (kmlObject) {
                         
                           kmlObjectsArray[current]= kmlObject;
                           ge.getFeatures().appendChild( kmlObjectsArray[current]);
						   current++;
                           	} else {
       
                             alert('Bad KML');
                             return;

                         }
		      });
            
          
}
			document.getdata.init(); 
  
}  
		  
  function toggleBuildings(){
  if (!buildings)
  {
  buildings = true;
  //toggleVisibilityNLs(false);
  ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, buildings);

  }
  else
  {
  buildings = false;
  toggleVisibilityNLs(true);
  ge.getLayerRoot().enableLayerById(ge.LAYER_BUILDINGS, buildings);
  }
  }
 
  function failureCB() { 

  }
  function createPlacemark(lat,lng){
  var placemark = ge.createPlacemark('');
  var point = ge.createPoint('');
  point.setLatitude(lat);
  point.setLongitude(lng);
  placemark.setGeometry(point);
  ge.getFeatures().appendChild(placemark);
  }
  function za(lat,lng,head,range,altitude,tilt){
    turning = false;
    latitude = lat;
    longitude = lng;
    heading = head;
    la.set(lat,lng,0,ge.ALTITUDE_RELATIVE_TO_GROUND,heading,tilt,range);
    if (!frameendEL){
    toggleFrameendEL();
    }
    ge.getOptions().setFlyToSpeed(.25);
    ge.getView().setAbstractView(la);
    turning = false;
 
    }
  
  function toggleFrameendEL(){
  if (!frameendEL){
  window.google.earth.addEventListener(ge, 'frameend', zoomAround);
  frameendEL = true;
   
  }else{
  google.earth.removeEventListener(ge, 'frameend', zoomAround);
  frameendEL = false;
  
  }
  
  }
  function zoomAround(){
              
    latemp = ge.getView().copyAsLookAt(ge.ALTITUDE_RELATIVE_TO_GROUND);

    
 }
  
function submitLocation() {
var address = document.getElementById('address').value;
geocoder.getLatLng(
address,
function(point) {
if (point && ge != null) {
   var la = ge.createLookAt('');
   la.set(point.y, point.x, 100, ge.ALTITUDE_RELATIVE_TO_GROUND,
         0, 0, 4000);
   ge.getView().setAbstractView(la);
}
}
);

}  
function create3dModel() {
var scptbuilding = document.createElement('script');
    scptbuilding.src = '3Dbuildings.js';
    document.body.appendChild(scptbuilding);

} 
  

  function buttonClick(lat,lng,head,range,altitude,tilt) {
    za(lat,lng,head,range,altitude,tilt); 
  }

 

 function updateOptions() {
  var options = ge.getOptions();
  var form = document.options;
  
  options.setStatusBarVisibility(form.statusbar.checked);
  options.setOverviewMapVisibility(form.overview.checked);
   }
  </script>
</head>
    
   <body onload='init()' id='body'>
    <div style='font-weight:bold; font-size: 16pt; font-family: arial; width:100%;'>
    <center>UCD project</center>
	</div>
	<span id="infobar"></span>
    <script>setInterval(function(){document.getElementById("infobar").innerHTML=new Date().toLocaleString()},1000)</script>

 
 

     <table>
    <tr>
      <td width=600>
        <div id='map3d' style='border: 1px solid silver; height: 600px;'>
      </div>
      </td>
	  
      <td width=600>
        <div id='map' style='border: 1px solid silver;height: 600px;'>
        </div>
      </td>
    </tr>
       
    </table>

  
  

   <table>
   
        <tr align=left>
        <td valign=top><input name="button" type="button" onClick="buttonClick(53.307632,-6.221766,0,700,0,85)" value="UCD"/>
       
		<input name="button" type="button" onClick="buttonClick(53.309501, -6.224827,0,100,0,80)" value="Computer Centre"/>
		<input name="button" type="button" onClick="buttonClick(53.309409, -6.226257,0,100,0,80)" value="Heath Centre"/>
		<input name="button" type="button" onClick="buttonClick(53.308192, -6.226594,0,100,0,80)" value="Student Centre"/>
		<input name="button" type="button" onClick="buttonClick(53.309269, -6.223879,0,100,0,80)" value="Computer Science&Infomation"/>
		<input name="button" type="button" onClick="buttonClick(53.308164, -6.229073,0,90,0,80)" value="Sport Centre"/>
		




        </td>
      </tr>
   </table>
    <div>
<form name='searchform' id='searchform' action='javascript:submitLocation();void(0);'>
<input type=text size=60 id='address'></input>
<input type=submit value='Go!'>
</form>
</div>

 <div id='options_container'> 
    <form name="options" action='javascript:updateOptions();'>
      <input type="checkbox" onclick='updateOptions()' name="statusbar" />Status Bar
      <br />
      <input type="checkbox" onclick='updateOptions()' name="overview" />Overview Map
      <br />
    

   </form>
     

  </div>  


</body>
</html>
